/*
 * This packet is the initial idenfitication by a client to select the 
 * security level to be used for the rest of the session.
 *
 * @author Jonathan Walsh (jwalsh8484@gmail.com)
 */

package egs.packets;

import java.nio.ByteBuffer;

public class SelectGamePacket extends Packet {

    short options;
    short packet_game_name;
    short packet_game_version;

    public SelectGamePacket( short options, 
                             short game_name, 
                             short game_version ) {
        
        /*Set up the header*/
        message_type = MSG_SELECT_GAME;
        this.game_name = 0;
        this.game_version = 0;
        data_area_size = 8; /*only four shorts in this packet*/
        
        /*Rest of the packet*/
        this.options = options;
        this.packet_game_name = game_name;
        this.packet_game_version = game_version;
    }
    
    public SelectGamePacket( byte[] raw ) {
        ByteBuffer buf = setHeaderNew( raw );
        
        options = buf.getShort();
        short empty = buf.getShort();
        packet_game_name = buf.getShort();
        packet_game_version = buf.getShort();
    }
	
    public byte[] getRaw() {
        ByteBuffer buf = makeBufferWithHeader( data_area_size );
        
        buf.putShort( options );
        buf.putShort( (short)0 );
        buf.putShort( packet_game_name );
        buf.putShort( packet_game_version );
        
        return buf.array();
    }
    
    
    public String toString() {
        String ret = super.toString() + "\noptions=" + options + " zero=" + 0;
        ret = ret + "\ngame_name=" + packet_game_name + " game_version="+packet_game_version;
        return ret;
    }
    
    public short get_options() { return options; }
    public short get_packet_game_name() { return packet_game_name; }
    public short get_packet_game_version() { return packet_game_version; }
}
